
package org.jinghouyu.json.utils;

import java.util.HashMap;
import java.util.Map;

public class ClassUtils {

	private static Map<String, Class<?>> classMap = new HashMap<String, Class<?>>();
	
	static {
		classMap.put("byte", byte.class);
		classMap.put("int", int.class);
		classMap.put("boolean", boolean.class);
		classMap.put("short", short.class);
		classMap.put("long", long.class);
		classMap.put("float", float.class);
		classMap.put("double", double.class);
		classMap.put("char", char.class);
	}
	/**
	 * 若classPath 是array 或者是基本类型也需要返回对应的class对象
	 * @param classPath
	 * @return
	 */
	public static Class<?> getClass(String classPath) {
		Class<?> clazz = null;
		if((clazz = classMap.get(classPath)) == null) {
			synchronized(ClassUtils.class) {
				if((clazz = classMap.get(classPath)) == null) {
					try {
						clazz = Class.forName(classPath);
						classMap.put(classPath, clazz);
					} catch (ClassNotFoundException e) {
						throw new RuntimeException(e);
					}
				}
			}
		}
		return clazz;
	}
}
